

package Controllers;
import Exception.DaoException;
import Interface.IReservation_Dao;        
import Models.Reservation;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;

public class Reservation_Controllers {
   
    private IReservation_Dao x;

    public Reservation_Controllers(IReservation_Dao x) {
        this.x = x;
    }

    Reservation_Controllers() {

    }

    public Reservation Validate2(String Name, String LastName, String PhoneNumber, String SeatNumber, String dateString)
            throws IllegalArgumentException, DaoException {
        
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        String dtStr = dateString.trim();  
        Date date;
        try {
             date = df.parse(dtStr);  
        } catch (ParseException e) {
            throw new IllegalArgumentException("Incorrect date format");
        }

        
        if (Calendar.getInstance().getTime().after(date)) {
            throw new IllegalArgumentException("Date has already passed");
        }

        if (Name.isEmpty() || LastName.isEmpty() || PhoneNumber.isEmpty() || SeatNumber.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Empty Field");
        
        } else if (PhoneNumber.matches("[0-9]+") == false) {
            JOptionPane.showMessageDialog(null, "Wrong Phone");
        } else if (PhoneNumber.length() > 10 || PhoneNumber.length() < 10) {
            JOptionPane.showMessageDialog(null, "Wrong Phone");
        } else if (SeatNumber.matches("[0-9]+")== false){
            JOptionPane.showMessageDialog(null, "Wrong Number of Seats");
        } else if (SeatNumber.length()>10 || SeatNumber.length()<10){
            JOptionPane.showMessageDialog(null,"Wrong Number of Seats" );
            
        } else {
            JOptionPane.showMessageDialog(null, "Success");
        }
        
        try {
            
            return x.ValidateReservation(Name, LastName, PhoneNumber,SeatNumber,date);
        } catch (DaoException e) {
            throw e;
        }

    }

}

